#include "venus.h"
#include "global_utils.h"

#include <stdio.h>

#ifdef VENUS_IS_WINDOWS
#include <windows.h>
#else
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#endif

namespace venus {
int Utils::TerminalWidth() {
#ifdef VENUS_IS_WINDOWS
  HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
  if (h == INVALID_HANDLE_VALUE || h == NULL) {
    fprintf(stderr, "GetStdHandle() call failed");
    return 80;
  }
  CONSOLE_SCREEN_BUFFER_INFO buffer_info = { 0 };
  GetConsoleScreenBufferInfo(h, &buffer_info);
  return buffer_info.dwSize.X;
#else
  struct winsize w;
  if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) < 0) {
    fprintf(stderr, "Error in ioctl() in TerminalWidth(): %d", errno);
    return 80;
  }
  return w.ws_col;
#endif
}

const int Utils::s_modulo[4] = { 1, 2, 0, 1 };
int Utils::line_num = 0;
std::string Utils::current_file;

int VenusOptions::core_num = 0;
bool VenusOptions::quick_render = false;
bool VenusOptions::quiet = false;
bool VenusOptions::verbose = true;
#if defined VENUS_IS_WINDOWS
const char *VenusOptions::project_path = "E:/workspace/venus/";
#elif defined VENUS_IS_LINUX
const char *VenusOptions::project_path = "/media/E/workspace/venus/";
#else
const char *VenusOptions::project_path = "";
#endif
} // namespace venus
